home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2001 May / may_2001.iso / intercd / root / Multimedia / ^DivX_Article / virtualdub / VirtualDub-source-1_4d / dTVdrv.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-25  |  9.4 KB  |  285 lines

  1. /////////////////////////////////////////////////////////////////////////////
  2. // dTVdrv.h
  3. /////////////////////////////////////////////////////////////////////////////
  4. // Copyright (c) 2000 John Adcock.  All rights reserved.
  5. /////////////////////////////////////////////////////////////////////////////
  6. //
  7. //    This file is subject to the terms of the GNU General Public License as
  8. //    published by the Free Software Foundation.  A copy of this license is
  9. //    included with this software distribution in the file COPYING.  If you
  10. //    do not have a copy, you may obtain a copy by writing to the Free
  11. //    Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  12. //
  13. //    This software is distributed in the hope that it will be useful,
  14. //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. //    GNU General Public License for more details
  17. /////////////////////////////////////////////////////////////////////////////
  18. //
  19. // This software was based on hwiodrv from the FreeTV project Those portions are
  20. // Copyright (C) Mathias Ellinger
  21. //
  22. /////////////////////////////////////////////////////////////////////////////
  23. // Change Log
  24. //
  25. // Date          Developer             Changes
  26. //
  27. // 19 Nov 1998   Mathias Ellinger      initial version
  28. //
  29. // 24 Jul 2000   John Adcock           Original dTV Release
  30. //                                     Added Memory Alloc functions
  31. //
  32. /////////////////////////////////////////////////////////////////////////////
  33.  
  34. #if ! defined (__DTVDRVDEF_H)
  35. #define __DTVDRVDEF_H
  36.  
  37. #define ALLOC_MEMORY_CONTIG 1
  38.  
  39. typedef struct _PageStruct
  40. {
  41.     DWORD dwSize;
  42.     DWORD dwPhysical;
  43. } TPageStruct, * PPageStruct;
  44.  
  45. typedef struct _MemStruct
  46. {
  47.     DWORD dwTotalSize;
  48.     DWORD dwPages;
  49.     DWORD dwHandle;
  50.     DWORD dwFlags;
  51.     void* dwUser;
  52. } TMemStruct, * PMemStruct;
  53.  
  54.  
  55. #if defined (WIN32)
  56.  
  57. #include <winioctl.h>
  58.  
  59. #elif defined(WIN95)
  60.  
  61.  
  62.  
  63. //
  64. // Macro definition for defining IOCTL and FSCTL function control codes.  Note
  65. // that function codes 0-2047 are reserved for Microsoft Corporation, and
  66. // 2048-4095 are reserved for customers.
  67. //
  68.  
  69. #define CTL_CODE( DeviceType, Function, Method, Access ) (                 \
  70.     ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) )
  71.  
  72. #define METHOD_BUFFERED                 0
  73. #define METHOD_IN_DIRECT                1
  74. #define METHOD_OUT_DIRECT               2
  75. #define METHOD_NEITHER                  3
  76.  
  77. //
  78. // Define the access check value for any access
  79. //
  80. //
  81. // The FILE_READ_ACCESS and FILE_WRITE_ACCESS constants are also defined in
  82. // ntioapi.h as FILE_READ_DATA and FILE_WRITE_DATA. The values for these
  83. // constants *MUST* always be in sync.
  84. //
  85.  
  86.  
  87. #define FILE_ANY_ACCESS                 0
  88. #define FILE_READ_ACCESS          ( 0x0001 )    // file & pipe
  89. #define FILE_WRITE_ACCESS         ( 0x0002 )    // file & pipe
  90.  
  91.  
  92. #elif defined (_NTKERNEL_)
  93.  
  94. extern "C" {
  95.  
  96. #include <devioctl.h>
  97.  
  98. }
  99.  
  100. //
  101. // Extract transfer type
  102. //
  103.  
  104. #define IOCTL_TRANSFER_TYPE( _iocontrol)   (_iocontrol & 0x3)
  105.  
  106.  
  107. #endif
  108.  
  109. #ifdef __cplusplus
  110. extern "C" {
  111. #endif
  112.  
  113.  
  114. #define FILE_DEVICE_DTV 0x8001
  115. #define DTV_BASE 0x800
  116.  
  117. #define DTV_READ_BYTE (DTV_BASE + 1)
  118. #define DTV_READ_WORD (DTV_BASE + 2)
  119. #define DTV_READ_DWORD (DTV_BASE + 3)
  120.  
  121. #define DTV_WRITE_BYTE (DTV_BASE + 4)
  122. #define DTV_WRITE_WORD (DTV_BASE + 5)
  123. #define DTV_WRITE_DWORD (DTV_BASE + 6)
  124.  
  125. #define DTV_GET_PCI_INFO (DTV_BASE + 7)
  126.  
  127. #define DTV_ALLOC_MEMORY (DTV_BASE + 8)
  128. #define DTV_FREE_MEMORY (DTV_BASE + 9)
  129.  
  130. #define DTV_MAP_MEMORY (DTV_BASE + 10)
  131. #define DTV_UNMAP_MEMORY (DTV_BASE + 11)
  132.  
  133. #define DTV_READ_MEMORY_DWORD (DTV_BASE + 12)
  134. #define DTV_WRITE_MEMORY_DWORD (DTV_BASE + 13)
  135.  
  136. #define DTV_READ_MEMORY_WORD (DTV_BASE + 14)
  137. #define DTV_WRITE_MEMORY_WORD (DTV_BASE + 15)
  138.  
  139. #define DTV_READ_MEMORY_BYTE (DTV_BASE + 16)
  140. #define DTV_WRITE_MEMORY_BYTE (DTV_BASE + 17)
  141.  
  142.  
  143.  
  144. //
  145. // The wrapped control codes as required by the system
  146. //
  147.  
  148. #define DTV_CTL_CODE(function,method) CTL_CODE( FILE_DEVICE_DTV,function,method,FILE_ANY_ACCESS)
  149.  
  150.  
  151. #define ioctlReadBYTE DTV_CTL_CODE( DTV_READ_BYTE, METHOD_OUT_DIRECT)
  152. #define ioctlReadWORD DTV_CTL_CODE( DTV_READ_WORD, METHOD_OUT_DIRECT)
  153. #define ioctlReadDWORD DTV_CTL_CODE( DTV_READ_DWORD, METHOD_OUT_DIRECT)
  154. #define ioctlWriteBYTE DTV_CTL_CODE( DTV_WRITE_BYTE, METHOD_IN_DIRECT)
  155. #define ioctlWriteWORD DTV_CTL_CODE( DTV_WRITE_WORD, METHOD_IN_DIRECT)
  156. #define ioctlWriteDWORD DTV_CTL_CODE( DTV_WRITE_DWORD, METHOD_IN_DIRECT)
  157. #define ioctlAllocMemory DTV_CTL_CODE( DTV_ALLOC_MEMORY, METHOD_BUFFERED)
  158. #define ioctlFreeMemory DTV_CTL_CODE( DTV_FREE_MEMORY, METHOD_IN_DIRECT)
  159. #define ioctlGetPCIInfo DTV_CTL_CODE( DTV_GET_PCI_INFO, METHOD_OUT_DIRECT)
  160. #define ioctlMapMemory DTV_CTL_CODE( DTV_MAP_MEMORY, METHOD_BUFFERED)
  161. #define ioctlUnmapMemory DTV_CTL_CODE( DTV_UNMAP_MEMORY, METHOD_BUFFERED)
  162. #define ioctlReadMemoryDWORD DTV_CTL_CODE( DTV_READ_MEMORY_DWORD, METHOD_OUT_DIRECT)
  163. #define ioctlWriteMemoryDWORD DTV_CTL_CODE( DTV_WRITE_MEMORY_DWORD, METHOD_IN_DIRECT)
  164. #define ioctlReadMemoryWORD DTV_CTL_CODE( DTV_READ_MEMORY_WORD, METHOD_OUT_DIRECT)
  165. #define ioctlWriteMemoryWORD DTV_CTL_CODE( DTV_WRITE_MEMORY_WORD, METHOD_IN_DIRECT)
  166. #define ioctlReadMemoryBYTE DTV_CTL_CODE( DTV_READ_MEMORY_BYTE, METHOD_OUT_DIRECT)
  167. #define ioctlWriteMemoryBYTE DTV_CTL_CODE( DTV_WRITE_MEMORY_BYTE, METHOD_IN_DIRECT)
  168.  
  169.  
  170. typedef struct tagDTVDRVParam
  171. {
  172.     DWORD   dwAddress;
  173.     DWORD   dwValue;
  174.     DWORD   dwFlags;
  175. } TDTVDRVParam, * PDTVDRVParam;
  176.  
  177. //---------------------------------------------------------------------------
  178. // This structure is taken from NTDDK.H, we use this only in WIN32 user mode
  179. //---------------------------------------------------------------------------
  180. #if defined (WIN32) || defined (WIN95)
  181.  
  182. typedef struct _PCI_COMMON_CONFIG
  183. {
  184.     USHORT  VendorID;                   // (ro)
  185.     USHORT  DeviceID;                   // (ro)
  186.     USHORT  Command;                    // Device control
  187.     USHORT  Status;
  188.     UCHAR   RevisionID;                 // (ro)
  189.     UCHAR   ProgIf;                     // (ro)
  190.     UCHAR   SubClass;                   // (ro)
  191.     UCHAR   BaseClass;                  // (ro)
  192.     UCHAR   CacheLineSize;              // (ro+)
  193.     UCHAR   LatencyTimer;               // (ro+)
  194.     UCHAR   HeaderType;                 // (ro)
  195.     UCHAR   BIST;                       // Built in self test
  196.  
  197.     union
  198.     {
  199.         struct _PCI_HEADER_TYPE_0
  200.         {
  201.             DWORD   BaseAddresses[6];
  202.             DWORD   CIS;
  203.             USHORT  SubVendorID;
  204.             USHORT  SubSystemID;
  205.             DWORD   ROMBaseAddress;
  206.             DWORD   Reserved2[2];
  207.  
  208.             UCHAR   InterruptLine;      //
  209.             UCHAR   InterruptPin;       // (ro)
  210.             UCHAR   MinimumGrant;       // (ro)
  211.             UCHAR   MaximumLatency;     // (ro)
  212.         } type0;
  213.     } u;
  214.     UCHAR   DeviceSpecific[192];
  215. } PCI_COMMON_CONFIG, *PPCI_COMMON_CONFIG;
  216.  
  217. #if defined (WIN32)
  218.  
  219. //---------------------------------------------------------------------------
  220. // The dTVdrv DLL application interface
  221. //---------------------------------------------------------------------------
  222.  
  223. int WINAPI isDriverOpened (void);
  224.  
  225. BYTE WINAPI readPort(WORD address);
  226. WORD WINAPI readPortW(WORD address);
  227. DWORD WINAPI readPortL(WORD address);
  228. void WINAPI writePort(WORD address, BYTE bValue);
  229. void WINAPI writePortW(WORD address, WORD uValue);
  230. void WINAPI writePortL(WORD address, DWORD dwValue);
  231.  
  232. DWORD WINAPI memoryAlloc(DWORD  dwLength,
  233.                           DWORD  dwFlags,
  234.                           PMemStruct* ppMemStruct);
  235.  
  236. DWORD WINAPI memoryFree(PMemStruct pMemStruct);
  237.  
  238. DWORD WINAPI pciGetHardwareResources(DWORD   dwVendorID,
  239.                                       DWORD   dwDeviceID,
  240.                                       PDWORD  pdwMemoryAddress,
  241.                                       PDWORD  pdwMemoryLength,
  242.                                       PDWORD  pdwSubSystemId);
  243.  
  244. DWORD WINAPI memoryMap(DWORD dwAddress, DWORD dwLength);
  245. void WINAPI memoryUnmap(DWORD dwAddress, DWORD dwLength);
  246. void WINAPI memoryWriteDWORD(DWORD dwAddress, DWORD dwValue);
  247. DWORD WINAPI memoryReadDWORD(DWORD dwAddress);
  248. void WINAPI memoryWriteWORD(DWORD dwAddress, WORD wValue);
  249. WORD WINAPI memoryReadWORD(DWORD dwAddress);
  250. void WINAPI memoryWriteBYTE(DWORD dwAddress, BYTE ucValue);
  251. BYTE WINAPI memoryReadBYTE(DWORD dwAddress);
  252.  
  253.  
  254. typedef int (WINAPI * PIsDriverOpened)(void);
  255. typedef DWORD (WINAPI * PMemoryRead)(DWORD dwAddress);
  256. typedef DWORD (WINAPI * PMemoryWrite)(DWORD dwAddress, DWORD dwValue);
  257.  
  258. typedef DWORD (WINAPI * PPCIGetHardwareResources)(DWORD   dwVendorID,
  259.                                                   DWORD   dwDeviceID,
  260.                                                   PDWORD  pdwMemoryAddress,
  261.                                                   PDWORD  pdwMemoryLength,
  262.                                                   PDWORD  pdwSubSystemId);
  263.  
  264. typedef DWORD (WINAPI * PMemoryAlloc)(DWORD  dwLength,
  265.                                         DWORD  dwFlags,
  266.                                         PMemStruct pMemStruct);
  267.  
  268. typedef DWORD (WINAPI * PMemoryFree)(DWORD dwUserAddress);
  269. typedef DWORD (WINAPI * PMemoryMap)(DWORD dwAddress, DWORD dwLength);
  270. typedef void * (WINAPI * PMemoryMapEx)(DWORD dwAddress, DWORD dwLength);
  271. typedef DWORD (WINAPI * PMemoryRead) (DWORD dwAddress);
  272. typedef DWORD (WINAPI * PMemoryWrite) (DWORD dwAddress, DWORD dwValue);
  273.  
  274. #endif
  275. #endif
  276.  
  277. #ifdef __cplusplus
  278. }
  279. #endif
  280.  
  281. #endif
  282.  
  283.  
  284.  
  285.